import modelExtend from '@/utils/modelExtend';
import HttpModel from '@/models/http';
import { doGet } from '@/services/http';
let basicService = {
  namespace: 'basicService',
  effects: {
    *getFetchPage({ payload, callback }, { call, put }) {
      const initParams = Object.assign(
        {
          current: 1,
          pagesize: 10,
        },
        payload,
      );
      const response = yield call(doGet, initParams);
      if (response.statusCode === '0') {
        const { data = {} } = response;
        const pageData = {
          list: data.records ?? [],
          pagination: {
            total: data?.total ?? 0,
            current: data.current,
            pageSize: data?.size ?? 10,
          },
        };
        pageData.list.forEach(
          t => (t.children = (t.methods ?? []).map(y => ({ ...y, checked: false }))),
        );
        yield put({ type: 'req', payload: { pageData: pageData } });
        if (callback) callback(response);
        return response;
      }
    },
  },
};
basicService = modelExtend(HttpModel, basicService);
export default basicService;
